#pragma once
#include <Jolt/Jolt.h>
#include <Jolt/Core/TempAllocator.h>
#include <common_header.h>

namespace primal
{
	class PhysicalTempAllocator : public JPH::TempAllocator
	{
	public:
		/// Constructs the allocator with a maximum allocatable size of inSize
		explicit						PhysicalTempAllocator(u32 inSize);

		/// Destructor, frees the block
		virtual							~PhysicalTempAllocator() override;

		// See: TempAllocator
		virtual void*                   Allocate(u32 inSize) override;

		// See: TempAllocator
		virtual void					Free(void* inAddress, u32 inSize) override;

		// Check if no allocations have been made
		bool							IsEmpty() const { return mTop == 0; }

	private:
		u8*                             mBase;							///< Base address of the memory block				
		u32							    mSize;							///< Size of the memory block
		u32							    mTop;						///< Current top of the stack

	};

	namespace phys
	{
		void* allocate_impl(size_t inSize);
		void free_impl(void* inBlock);
		void* aligned_allocate_impl(size_t inSize, size_t inAlignment);
		void aligned_free_impl(void* inBlock);
	}
}